package networkinterface;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * 
 * @author Michael & Pierre
 *
 */
/**
 * Thread which will be used to send a message
 */
public class SendingThread extends Thread {

	private byte[] myMessage;
	private String dest;
	private int port;
	
	/**
	 * @param myMessage message which will be sent
	 * @param dest address of the recipient of the message
	 * @param port remote port where the message will be sent
	 */
	public SendingThread(byte[] myMessage, String dest, int port) {
		this.myMessage = myMessage;
		this.dest = dest;
		this.port = port;
	}
	
	public void run() {
		DatagramSocket mySendSock;

		try {

			mySendSock = new DatagramSocket();
			mySendSock.send(new DatagramPacket(myMessage, myMessage.length, 
						InetAddress.getByName(dest), port));
			mySendSock.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
